package com.wise.service.portal.content.applicationarticles;

import com.wise.entities.content.ApplicationArticle;
import com.wise.entities.content.ArticleStatus;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoPageList;
import com.wise.framework.restful.PageResultList;
import com.wise.summer.v1.portal.content.applicationarticles.ListApplicationArticles;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

/**
 * @author hejiawei
 * @date 2020/10/27 12:50
 */
@Service
@SummerService
public class ListApplicationArticlesService implements SummerServiceBean<ListApplicationArticles> {
    @Override
    public void sum(ListApplicationArticles model) {
        SqlSelect sql = SqlSelect.selec("*")
                .fromClassName(ApplicationArticle.class)
                .eq(StringUtils.isNotBlank(model.getColumnId()), ApplicationArticle._columnId, model.getColumnId())
                .eq(ApplicationArticle._state, ArticleStatus.PUBLISH.value())
                .eqLang(ApplicationArticle._lang)
                .order_by(ApplicationArticle._sort)
                .order_by(ApplicationArticle._publishTime + " desc");

        PageResultList<ListApplicationArticles.Result> articleList = DaoPageList.s(ListApplicationArticles.Result.class, sql, model.getStart(), model.getLimit());
        model.setSummerResult(articleList);
    }
}
